package com.WOWTradeNews.services;

import android.content.Context;
import android.content.Intent;

public class Mail {
	// you need config the mail app in your android moble first,and the mail will send by the mail app. and there are one big bug:  
    //you can't send the mail Silently and you need to click the send button  
    public static final int sendMailByIntent(Context context, String[] reciver, String body) {  
        //String[] reciver = new String[] { "181712000@qq.com" };  
        String[] mySbuject = new String[] { "test" };  
        String myCc = "cc";  
        //String mybody = "测试Email Intent";  
        Intent myIntent = new Intent(android.content.Intent.ACTION_SEND);  
        myIntent.setType("plain/text");  
        myIntent.putExtra(android.content.Intent.EXTRA_EMAIL, reciver);  
        myIntent.putExtra(android.content.Intent.EXTRA_CC, myCc);  
        myIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySbuject);  
        myIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);  
        context.startActivity(Intent.createChooser(myIntent, "mail test"));  
  
        return 1;  
  
    }  
   /*this method can't be used in android mobile successful,but it can run normally in PC. 
    Because it will cause the java.lang.NoClassDefFoundError: javax.activation.DataHandler error 
    May be there are some way to solove it ......there are always javax package not found in android virtual mobile. 
    By the way ,the method use Apache mail jar       
    */  
    /*public int sendMailByApache() {  
  
        try {  
            HtmlEmail email = new HtmlEmail();  
            // 这里是发送服务器的名字  
            email.setHostName("smtp.gmail.com");  
            // 编码集的设置  
            email.setTLS(true);  
            email.setSSL(true);  
  
            email.setCharset("gbk");  
            // 收件人的邮箱  
            email.addTo("181712000@qq.com");  
            // 发送人的邮箱  
            email.setFrom("wcf0000@gmail.com");  
            // 如果需要认证信息的话，设置认证：用户名-密码。分别为发件人在邮件服务器上的注册名称和密码  
            email.setAuthentication("wcf1000", "00000");  
            email.setSubject("测试Email Apache");  
            // 要发送的信息  
            email.setMsg("测试Email Apache");  
            // 发送  
            email.send();  
        } catch (EmailException e) {  
            // TODO Auto-generated catch block  
            Log.i("IcetestActivity", e.getMessage());  
        }  
  
        return 1;  
    }  */
/* 
 * this method use javamail for android ,it is a good jar, 
 * you can see the demo in http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android 
 * and you also need three jars ,which I offered in attachement 
 *  
 * */  
    /*public int sendMailByJavaMail() {  
        Mail m = new Mail("wcfXXXX@gmail.com", "XXXXX");  
        m.set_debuggable(true);  
        String[] toArr = {"18170000@qq.com"};   
        m.set_to(toArr);  
        m.set_from("18170000@qq.com");  
        m.set_subject("This is an email sent using icetest from an Android device");  
        m.setBody("Email body. test by Java Mail");  
        try {  
            //m.addAttachment("/sdcard/filelocation");   
            if(m.send()) {   
            Log.i("IcetestActivity","Email was sent successfully.");  
                          
            } else {  
                Log.i("IcetestActivity","Email was sent failed.");  
            }  
        } catch (Exception e) {  
            // Toast.makeText(MailApp.this,  
            // "There was a problem sending the email.",  
            // Toast.LENGTH_LONG).show();  
            Log.e("MailApp", "Could not send email", e);  
        }  
  
        return 1;  
    }  */
}
